package com.wardrobe.soa.backend.shop;

import com.wardrobe.dao.shop.ShopDao;
import com.wardrobe.domain.common.BackEndFromBean;
import com.wardrobe.domain.shop.ShopFromBean;
import com.wardrobe.domain.shop.ShopShowBean;
import com.wardrobe.soa.api.user.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/11/16.
 */
@Service
public class BackShopService {
    @Autowired
    private ShopDao shopDao;
    @Autowired
    private UserDao userDao;

    public int modifyShop(BackEndFromBean fromBean){
        fromBean.setUpdateTime(new Date());
        return shopDao.updateShop(fromBean);
    }

    public List<ShopShowBean> getShopList(ShopFromBean fromBean){
        return shopDao.selectShopList(fromBean);
    }

    public long countShop(ShopFromBean fromBean){
        return shopDao.countShop(fromBean);
    }

    public ShopShowBean getShop(String nickName){
        List<Map<String, Object>> userByMobile = userDao.getUserByMobile(nickName);
        if (userByMobile.size()==0){
            return null;
        }
        return shopDao.selectShopByUserId((Long) userByMobile.get(0).get("id"));
    }
    public ShopShowBean getOneShopDetail(long shopId){
        return shopDao.selectShopById(shopId);
    }
}
